import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Test {

    public static String VigenèreCipher(String key, String plaintext) {
        StringBuffer ciphertext = new StringBuffer();
        key = key.replaceAll("[^a-zA-Z]", "").toLowerCase();
        if (key.isEmpty()) throw new IllegalArgumentException("无效密钥");

        int[] arrKey = key.chars().map(c -> c - 'a').toArray();
        int keyIndex = 0;

        for (char ch : plaintext.toCharArray()) {
            if (Character.isLetter(ch)) {
                boolean isUpper = Character.isUpperCase(ch);
                int plainNum = Character.toLowerCase(ch) - 'a';
                int cipherNum = (plainNum + arrKey[keyIndex % arrKey.length]) % 26;
                ciphertext.append((char) (cipherNum + (isUpper ? 'A' : 'a')));
                keyIndex++;
            } else {
                ciphertext.append(ch); // 非字母字符原样保留
            }
        }
        return ciphertext.toString();
    }

    public static void countFrequency(String str) {
        HashMap<Character, Integer> freq = new HashMap<>();
        int total = 0;
        for (char ch : str.toCharArray()) {
            if (Character.isLetter(ch)) {
                char c = Character.toUpperCase(ch);
                freq.put(c, freq.getOrDefault(c, 0) + 1);
                total++;
            }
        }
        int finalTotal = total;
        freq.forEach((k, v) -> System.out.printf("%c : %.4f%n", k, v * 1.0 / finalTotal));
    }

    //Vigenère加密算法
    /*public static String VigenèreCipher(String key, String plaintext){

        StringBuffer ciphertext = new StringBuffer();

        //密钥&明文全部字母转为小写
        key = key.toLowerCase();
        plaintext = plaintext.toLowerCase();

        //存储密钥对应的数字
        int[] arrKey = new int[key.length()];
        for(int i = 0; i < key.length(); i++){
            char ch = key.charAt(i);
            //a-z --> 0-25
            arrKey[i] = (int)(ch - 'a');
        }

        //存储明文对应的数字
        int[] arrPlain = new int[plaintext.length()];
        for(int i = 0; i < plaintext.length(); i++){
            char ch = plaintext.charAt(i);
            //a-z --> 0-25
            arrPlain[i] = (int)(ch - 'a');
        }

        //对应分组相加
        int indexOfPlain = 0;
        int[] arrResult = new int[plaintext.length()];
        for(int i = 0; i < plaintext.length(); i++){
            int index = i % key.length();
            arrResult[i] = (arrKey[index] + arrPlain[i]) % 26;
        }

        //根据数字，获得密文
        for(int i = 0; i < arrResult.length; i++){
            //0-25 --> A-Z
            char ch = (char)(arrResult[i] + 'A');
            ciphertext.append(ch);
        }
        return ciphertext.toString();
    }

    //统计字母出现频率
    public static void countFrequency(String str){
        HashMap<Character, Integer> map = new HashMap<>();
        for(int i = 0; i < str.length(); i++){
            char ch = str.charAt(i);
            if(!map.containsKey(ch)){
                map.put(ch,1);
            }else{
                int val = map.get(ch);
                map.replace(ch, val, val+1);
            }
        }

        Set<Map.Entry<Character, Integer>> entries = map.entrySet();
        for(Map.Entry<Character, Integer> entry : entries){
            System.out.printf("%c : %.4f \n", entry.getKey(), entry.getValue()*1.0/str.length());
        }
    }*/
    public static void main(String[] args) {
        Scanner in  = new Scanner(System.in);
        String key = in.nextLine();
        String plaintext = in.nextLine();

        String ciphertext = VigenèreCipher(key, plaintext);
        System.out.println("密文:" + ciphertext);

        System.out.println("明文中各字母出现频率:");
        countFrequency(plaintext);

        System.out.println("密文中各字母出现频率:");
        countFrequency(ciphertext);
    }
}
